//
//  HDBNavigationViewController.swift
//  HDBWeibo
//
//  Created by leidon on 2016/11/17.
//  Copyright © 2016年 BONC. All rights reserved.
//

import UIKit

class HDBNavigationViewController: UINavigationController {

    override func viewDidLoad() {
        //隐藏导航栏  隐藏 那就得自定义    ** 如果隐藏导航栏 ，自动view缩进20  （往上移20）
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //print(viewController)
        
        if let vc = viewController as? HDBBaseViewController{
            //给导航天加一个左边的返回按钮
            var title = "返回"
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? "返回"
            }else if childViewControllers.count == 0{
                
            }
            
            if childViewControllers.count != 0 {
                vc.naviItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent),isBack : true)
            }
            
        }
        
        //栈底的控制器不隐藏
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: true)
       // print(viewController)  感觉自己调皮的不要不要的～
        
    } 
    
    //返回上一个界面
    @objc private func popToParent(){
        //❄️ 
        popViewController(animated: true)
    }
}
